import { fileURLToPath, URL } from "node:url";
import { resolve } from "path";

import { defineConfig } from "vite";
import vue from "@vitejs/plugin-vue";

import externalGlobals from "rollup-plugin-external-globals";

const plugins = [vue()],
  globals = externalGlobals({ vue: "Vue" });
if (process.env.NODE_ENV !== "production")
  plugins.push(
    {
      transformIndexHtml: (html) =>
        html.replace("vue.runtime.global.prod.", "vue.runtime.global."),
    },
    globals
  );

// https://vitejs.dev/config/
export default defineConfig({
  plugins,
  resolve: {
    alias: {
      "@": fileURLToPath(new URL("./src", import.meta.url)),
    },
  },
  server: {
    host: "0.0.0.0",
    port: 3310,
    open:true,
  },
  build: {
    assetsInlineLimit: 0,
    rollupOptions: {
      external: ["vue"],
      plugins: [globals],
      input: {
        main: resolve(__dirname, "index.html"),
        // pc: resolve(__dirname, "pc.html"),
      },
    },
  },
});
